"""
Python程序设计语言第6周：函数

打印2021年12个月的天数，要求定义两个函数

is_leapyear(year)
days_in_year_month(year,month)
"""

def is_leapyear(year):
    if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0):
        return True

    return False

def days_in_year_month(year,month):
    days = 0
    if month == 1 or month == 3 or month == 5 or month == 7 or month == 8 or month == 10 or month == 12:
        days = 31
    elif month == 4 or month == 6 or month == 9 or month == 11:
        days = 30
    elif month == 2:
        days = 28
        if is_leapyear(year):
            days += 1

    return days

#打印2021年1~12月份的天数
year = 2021

for month in range(1, 13):
    days = days_in_year_month(year, month)
    print(str(year) + "年" + str(month) + "月有" + str(days) + "天")